package com.test.nnooolwdeaer.activity_fragment_wooden.loan_wooden;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.test.nnooolwdeaer.bean_wooden.StaticVariate_wooden;
import com.test.nnooolwdeaer.bean_wooden.user_info_wooden.LoanApplyDetailInfo_wooden;
import com.test.nnooolwdeaer.constant_wooden.Constant_wooden;
import com.test.nnooolwdeaer.util_wooden.StringUtil_wooden;
import com.test.nnooolwdeaer.util_wooden.ThreadUtil_wooden;
import com.test.nnooolwdeaer.util_wooden.http_wooden.HttpManager_wooden;
import com.test.nnooolwdeaer.view_wooden.module_wooden.AddBankAccountView_Cote_wooden;
import com.test.nnooolwdeaer.view_wooden.module_wooden.ShowWalletAccountListView_Cote_wooden;
import com.test.nnooolwdeaer.view_wooden.widget_wooden.TitleView_wooden;
import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseLoanActivity_wooden;


public class LoanApplyActivity_wooden extends BaseLoanActivity_wooden {

    private TextView loanAmountTv_wooden, loanAmountTv1_wooden, loanAmountTv2_wooden;
    private TextView loanTermTv_wooden, disburseAmountTv_wooden, serviceFeeTv1_wooden, repaymentAmountTv_wooden,
            interestTv_wooden, serviceFeeTv2_wooden, overduePenaltyInterestTv_wooden;
    private Button applyBn_wooden;

    //科特VAT
    private View coteVatView1_wooden, coteVatView2_wooden;
    private TextView coteVatTv1_wooden, coteVatTv2_wooden;

    private ShowWalletAccountListView_Cote_wooden showWalletAccountListView_cote_wooden;
    private AddBankAccountView_Cote_wooden addBankAccountView_cote_wooden;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loan_apply_wooden);
        init_wooden();
    }

    private void init_wooden(){
        TitleView_wooden titleView = findViewById(R.id.activity_loan_apply_view_title);
        setBackBtn_wooden(titleView.getBackIb_wooden());

        loanAmountTv_wooden = findViewById(R.id.activity_loan_apply_tv_loan_amount);
        loanAmountTv1_wooden = findViewById(R.id.activity_loan_apply_tv_loan_amount_1);
        loanAmountTv2_wooden = findViewById(R.id.activity_loan_apply_tv_loan_amount_2);
        loanTermTv_wooden = findViewById(R.id.activity_loan_apply_tv_loan_term);
        disburseAmountTv_wooden = findViewById(R.id.activity_loan_apply_tv_disburse_amount);
        serviceFeeTv1_wooden = findViewById(R.id.activity_loan_apply_tv_service_fee_1);
        repaymentAmountTv_wooden = findViewById(R.id.activity_loan_apply_tv_repayment_amount);
        interestTv_wooden = findViewById(R.id.activity_loan_apply_tv_interest);
        serviceFeeTv2_wooden = findViewById(R.id.activity_loan_apply_tv_service_fee_2);
        overduePenaltyInterestTv_wooden = findViewById(R.id.activity_loan_apply_tv_overdue_penalty_interest);
        applyBn_wooden = findViewById(R.id.activity_loan_apply_btn_apply);

        coteVatView1_wooden = findViewById(R.id.activity_loan_apply_layout_cote_vat_1);
        coteVatView2_wooden = findViewById(R.id.activity_loan_apply_layout_cote_vat_2);
        coteVatTv1_wooden = findViewById(R.id.activity_loan_apply_tv_cote_vat_1);
        coteVatTv2_wooden = findViewById(R.id.activity_loan_apply_tv_cote_vat_2);

        showWalletAccountListView_cote_wooden = findViewById(R.id.activity_loan_apply_view_show_account_view);
        addBankAccountView_cote_wooden = findViewById(R.id.activity_loan_apply_view_add_account_view);

        applyBn_wooden.setOnClickListener(v ->
            ThreadUtil_wooden.getInstance_wooden().runOnChildThread_wooden(() -> {
                HttpManager_wooden.getInstance_wooden().saveUserBuriedPointAndUpload((this.getClass().getSimpleName()+"_CLICK").toUpperCase());
                try {
                    Thread.sleep(300);
                } catch (InterruptedException e) {
                    if (Constant_wooden.Debug) e.printStackTrace();
                }
                HttpManager_wooden.getInstance_wooden().loanApply_wooden();
            }));

        //科特VAT
        boolean isCote = StaticVariate_wooden.Select_Country_wooden.equalsIgnoreCase(Constant_wooden.Country_Cote_wooden);
        coteVatView1_wooden.setVisibility(isCote ? View.VISIBLE:View.GONE);
        coteVatView2_wooden.setVisibility(isCote ? View.VISIBLE:View.GONE);

    }

    @Override
    protected void onResume() {
        super.onResume();
        HttpManager_wooden.getInstance_wooden().requestLoanApplyDetail_wooden();
    }

    @SuppressLint("SetTextI18n")
    public void onLoanApplyDetailResponse_wooden(){

        //货币单位
        String moneyUnit = StringUtil_wooden.getSafeString_wooden(StaticVariate_wooden.getMoneyUnit_wooden()).toUpperCase();

//        if (StaticVariate_wooden.isTestAccount()){
//
//            loanAmountTv_wooden.setText(moneyUnit+" 100000");
//            loanAmountTv1_wooden.setText(" 100000 "+moneyUnit);
//            loanAmountTv2_wooden.setText(" 100000 "+moneyUnit);
//            loanTermTv_wooden.setText("365 "+getString(R.string.word_days));
//
//            disburseAmountTv_wooden.setText("124000 "+moneyUnit);
//            serviceFeeTv1_wooden.setText("0 "+moneyUnit);
//            serviceFeeTv2_wooden.setText("0 "+moneyUnit);
//            repaymentAmountTv_wooden.setText("124000 "+moneyUnit);
//            interestTv_wooden.setText("24000 "+moneyUnit);
//
//            overduePenaltyInterestTv_wooden.setText("3" + getString(R.string.activity_loan_apply_rate_suffix));
//
//            //科特Vat
//            coteVatTv1_wooden.setText("0 "+moneyUnit);
//            coteVatTv2_wooden.setText("0 "+moneyUnit);
//
//            if (StaticVariate_wooden.Select_Country_wooden.equalsIgnoreCase(Constant_wooden.Country_Cote_wooden))
//                HttpManager_wooden.getInstance_wooden().fetchBoundBankAccount_Cote_wooden();
//
//            return;
//        }

        loanAmountTv_wooden.setText(moneyUnit+" "+ LoanApplyDetailInfo_wooden.getInstance_wooden().getAmount_wooden());
        loanAmountTv1_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getAmount_wooden()+" "+moneyUnit);
        loanAmountTv2_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getAmount_wooden()+" "+moneyUnit);
        loanTermTv_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getDays_wooden()+" "+getString(R.string.word_days));

        disburseAmountTv_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getRealAmount_wooden()+" "+moneyUnit);
        serviceFeeTv1_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getProcessingFee_wooden()+" "+moneyUnit);
        serviceFeeTv2_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getRepayProFee_wooden()+" "+moneyUnit);
        repaymentAmountTv_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getRepayAmount_wooden()+" "+moneyUnit);
        interestTv_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getInterest_wooden()+" "+moneyUnit);

        String overduePenaltyInterest = (StringUtil_wooden.safeParseDouble_wooden(LoanApplyDetailInfo_wooden.getInstance_wooden().getOverdueRate_wooden())*100) + getString(R.string.activity_loan_apply_rate_suffix);
        overduePenaltyInterestTv_wooden.setText(overduePenaltyInterest);

        //科特Vat
        coteVatTv1_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getProcessingVatFee_wooden()+" "+moneyUnit);
        coteVatTv2_wooden.setText(LoanApplyDetailInfo_wooden.getInstance_wooden().getRepayProVatFee_wooden()+" "+moneyUnit);

        if (StaticVariate_wooden.Select_Country_wooden.equalsIgnoreCase(Constant_wooden.Country_Cote_wooden))
            HttpManager_wooden.getInstance_wooden().fetchBoundBankAccount_Cote_wooden();
    }

    public void onFetchBankAccountListResponse_Cote_wooden(){
        showWalletAccountListView_cote_wooden.updateAccountList_wooden();
        addBankAccountView_cote_wooden.updateAccountList_wooden();
    }

    public void onLoanApplyResponse_wooden(){
        HttpManager_wooden.getInstance_wooden().requestUserProcess_wooden();
    }
}